package projectisd.client;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

/** 
 * Dit is de klas die de functies uit Vak die de functies Async maakt en functies aanmaakt
 * om de array list te updaten, verwijderen en iets aan toe te voegen daaraan.
 * @author Team 2
 * @version 7.0
 */

public class VakDelegate {
    private ProjectServiceAsync projectService = GWT.create(ProjectService.class);
    VakGUI gui;
    
    void listVakken() {
    	projectService.listVakken(new AsyncCallback<List<Vak>> () {
                    public void onFailure(Throwable caught) {
                        gui.service_eventListVakFailed(caught);
                    }
        
                    public void onSuccess(List<Vak> result) {
                        gui.service_eventListRetrievedFromService(result);
                        
                    }
        }//end of inner class
        );//end of listVakkens method call.
    }
    
    void addVak(final Vak vak) {
        projectService.addVak(vak, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventAddVakFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventAddVakSuccessful();
            }
        }//end of inner class
        );//end of addVak method call.        
    }

    void updateVak(final Vak vak) {
    	projectService.updateVak(vak, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventUpdateVakFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventUpdateSuccessful();
            }
        }//end of inner class
        );//end of updateVak method call.        
    }

    void removeVak(final Vak vak) {
    	projectService.removeVak(vak, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventRemoveVakFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventRemoveVakSuccessful();
            }
        }//end of inner class
        );//end of updateVak method call.        
    }
    
}
